Completed
Push — master ( 552101...beada9 )
by greg
03:14
created

metas.js ➔ get   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
dl 0
loc 23
rs 9.0856
nop 1
1
import {
2
  cmsData
3
  ,config
4
} from '../../'
5
6
export function add(tpl, json, type, obj = {}, date = null, realType = 'draft') {
7
  let meta = config.meta.name
8
9
  var currentDate = (date != null && date !== '') ? date : new Date()
10
  var abeUrl = (type === 'publish') ? json[meta].link : cmsData.fileAttr.add(json[meta].link, 'd' + cmsData.revision.removeStatusAndDateFromFileName(currentDate.toISOString())) + ''
11
12
  if(json[meta].date == null) {
13
    json[meta].date = currentDate
14
  }
15
  json[meta].latest = {
16
    date: currentDate,
17
    abeUrl: abeUrl
18
  }
19
  json[meta].status = realType === 'reject' ? 'draft' : realType
20
  if(json[meta][type] == null) {
21
    json[meta][type] = JSON.parse(JSON.stringify(obj))
22
    json[meta][type].date = currentDate
23
    json[meta][type].abeUrl = abeUrl
24
  }
25
  json[meta][type].latest = JSON.parse(JSON.stringify(obj))
26
  json[meta][type].latest.date = currentDate
27
  json[meta][type].latest.abeUrl = abeUrl
28
}
29